package com.hzb.service.impl;

import com.hzb.dao.UserFilesDao;
import com.hzb.entity.User;
import com.hzb.entity.UserFile;
import com.hzb.service.UserFileService;
import com.hzb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 功能描述
 *
 * @author 和振斌
 * @date 2020/7/31
 * @return
 */
@Service
@Transactional
public class UserFileServiceImpl implements UserFileService {

    @Autowired
    private UserFilesDao userFilesDao;

    @Override
    public List<UserFile> findByUserId(Integer id) {
        return userFilesDao.findByUserId(id);
    }


    /**上传文件
     * */
    @Override
    public void save(UserFile userFile) {
        //判断是否图片，思路，当类型中有image时说明当前类型一定为图片类型
        String isimg = userFile.getType().startsWith("image")?"是":"否";
        userFile.setIsimg(isimg);
        userFile.setDowncounts(0);
        userFile.setUploadTime(new Date());
        System.out.println(userFile);
        userFilesDao.save(userFile);
    }

    @Override
    public UserFile findFileById(Integer id) {
        return userFilesDao.findFileById(id);
    }

    @Override
    public void update(UserFile userFile) {
        userFilesDao.update(userFile);
    }

    @Override
    public void delete(Integer id) {
        userFilesDao.delete(id);
    }
}
